package org.dromara.system.service.impl;

import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.exception.ServiceException;
import org.dromara.common.core.utils.MapstructUtils;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.system.domain.SysDevice;
import org.dromara.system.domain.SysUserDevice;
import org.dromara.system.domain.bo.SysDeviceBo;
import org.dromara.system.domain.vo.SysDeviceVo;
import org.dromara.system.mapper.SysDeviceMapper;
import org.dromara.system.mapper.SysUserDeviceMapper;
import org.dromara.system.service.ISysDeviceService;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * 设备信息 服务层处理
 *
 * @author Lion Li
 */
@RequiredArgsConstructor
@Service
public class SysDeviceServiceImpl implements ISysDeviceService {

    private final SysDeviceMapper baseMapper;
    private final SysUserDeviceMapper userDeviceMapper;

    /**
     * 查询设备信息集合
     *
     * @param Device 设备信息
     * @return 设备信息集合
     */
    @Override
    public List<SysDeviceVo> selectDeviceList(SysDeviceBo Device) {
        LambdaQueryWrapper<SysDevice> lqw = buildQueryWrapper(Device);
        return baseMapper.selectVoList(lqw);
    }

    @Override
    public List<Tree<Long>> selectDeviceTreeList(SysDeviceBo Device) {
        return null;
    }

    @Override
    public List<Tree<Long>> buildDeviceTreeSelect(List<SysDeviceVo> Devices) {
        return null;
    }

    @Override
    public List<Long> selectDeviceListByRoleId(Long roleId) {
        return null;
    }

    private LambdaQueryWrapper<SysDevice> buildQueryWrapper(SysDeviceBo bo) {
        LambdaQueryWrapper<SysDevice> lqw = Wrappers.lambdaQuery();
        return lqw;
    }

    /**
     * 通过设备ID查询设备信息
     *
     * @param DeviceId 设备ID
     * @return 角色对象信息
     */
    @Override
    public SysDeviceVo selectDeviceById(Long DeviceId) {
        return baseMapper.selectVoById(DeviceId);
    }

    @Override
    public String selectDeviceNameByIds(String DeviceIds) {
        return null;
    }

    @Override
    public long selectNormalChildrenDeviceById(Long DeviceId) {
        return 0;
    }

    @Override
    public boolean hasChildByDeviceId(Long DeviceId) {
        return false;
    }

    @Override
    public boolean checkDeviceExistUser(Long DeviceId) {
        return false;
    }

    @Override
    public boolean checkDeviceNameUnique(SysDeviceBo Device) {
        return false;
    }

    @Override
    public void checkDeviceDataScope(Long DeviceId) {

    }

    @Override
    public void checkDeviceDataScope(List<Long> DeviceIds) {

    }

    /**
     * 删除设备信息
     *
     * @param DeviceId 设备ID
     * @return 结果
     */
    @Override
    public int deleteDeviceById(Long DeviceId) {
        return baseMapper.deleteById(DeviceId);
    }

    /**
     * 新增保存设备信息
     *
     * @param bo 设备信息
     * @return 结果
     */
    @Override
    public int insertDevice(SysDeviceBo bo) {
        SysDevice Device = MapstructUtils.convert(bo, SysDevice.class);
        return baseMapper.insert(Device);
    }

    /**
     * 修改保存设备信息
     *
     * @param bo 设备信息
     * @return 结果
     */
    @Override
    public int updateDevice(SysDeviceBo bo) {
        SysDevice Device = MapstructUtils.convert(bo, SysDevice.class);
        return baseMapper.updateById(Device);
    }
}
